﻿<navigation:Page x:Class="ExampleApplication.Examples.EditExistingShapes" x:Name="me"
           xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
           xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
           xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
           xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="EditExistingShapes Page"
           xmlns:deepearth="http://deepearth.codeplex.com/xaml"
           xmlns:nearmap ="clr-namespace:DeepEarth.Map.TileSources;assembly=DeepEarth.TileSources.NearMap">

    <Grid x:Name="LayoutRoot">
        <Grid.Resources>
            <deepearth:DoubleCollectionConverter x:Key="doubleCollectionConverter"></deepearth:DoubleCollectionConverter>

            <deepearth:GeoItems x:Name="geoItems"></deepearth:GeoItems>

            <deepearth:TemplateSelector x:Key="mapTemplateSelector">

                <DataTemplate  deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.PushpinGeometry, DeepEarth.Toolkit.Geometry">
                    <deepearth:Pushpin Position="{Binding Position, Mode=TwoWay}" PositionOrigin="0.5,1" EnableDrag="True" Scale="2"></deepearth:Pushpin>
                </DataTemplate>

                <DataTemplate  deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.LineStringGeometry, DeepEarth.Toolkit.Geometry">
                    <deepearth:LineString Locations="{Binding Locations}" Stroke="Yellow" StrokeThickness="5" StrokeDashArray="{Binding StrokeDashArray, Converter={StaticResource doubleCollectionConverter}}">
                    </deepearth:LineString>
                </DataTemplate>

                <DataTemplate  deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.PolygonGeometry, DeepEarth.Toolkit.Geometry">
                    <deepearth:Polygon OuterRing="{Binding Locations}" StrokeThickness="{Binding StrokeThickness}" Stroke="{Binding Stroke}" Fill="{Binding Fill}">
                    </deepearth:Polygon>
                </DataTemplate>

            </deepearth:TemplateSelector>

            <deepearth:TemplateSelector x:Key="layerTemplateSelector">

                <DataTemplate deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Controls.DrawnObjectsCollection, DeepEarth.Toolkit.Controls.Digitizer">
                    <TextBlock Text="Drawn Objects" Foreground="White"></TextBlock>
                </DataTemplate>

                <DataTemplate deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.PushpinGeometry, DeepEarth.Toolkit.Geometry">
                    <StackPanel Orientation="Vertical">
                    <StackPanel Orientation="Horizontal" Margin="0 0 5 0">
                        <TextBlock Text="Drag the pin on the map!" Foreground="White" Margin="0 0 5 0"></TextBlock>
                        <deepearth:Pushpin></deepearth:Pushpin>
                    </StackPanel>
                        <StackPanel Orientation="Horizontal" Margin="0 0 5 0">
                            <TextBlock Text="Lat: " Foreground="White"></TextBlock>
                            <TextBlock Text="{Binding Position.Latitude}" Foreground="White"></TextBlock>
                        </StackPanel>
                        <StackPanel Orientation="Horizontal">
                            <TextBlock Text="Lon: " Foreground="White"></TextBlock>
                            <TextBlock Text="{Binding Position.Longitude}" Foreground="White"></TextBlock>
                        </StackPanel>
                    </StackPanel>
                </DataTemplate>

                <DataTemplate  deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.LineStringGeometry, DeepEarth.Toolkit.Geometry">
                    <StackPanel Orientation="Horizontal" Margin="0 0 5 0">
                        <TextBlock Text="Line" Foreground="White" Margin="0 0 5 0"></TextBlock>
                        <deepearth:LocationPath Width="20" Height="20" Locations="{Binding Locations}" Stroke="{Binding Stroke}" StrokeThickness="2"></deepearth:LocationPath>
                    </StackPanel>
                </DataTemplate>

                <DataTemplate  deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.PolygonGeometry, DeepEarth.Toolkit.Geometry">
                    <StackPanel Orientation="Horizontal" Margin="0 0 5 0">
                        <TextBlock Text="Polygon" Foreground="White" Margin="0 0 5 0"></TextBlock>
                        <deepearth:LocationPath Width="80" Height="80" Locations="{Binding Locations}" Stroke="{Binding Stroke}" Fill="{Binding Fill}" StrokeThickness="2"></deepearth:LocationPath>
                    </StackPanel>
                </DataTemplate>

                <DataTemplate  deepearth:TemplateSelector.DataType="DeepEarth.Toolkit.Geometry.Data.GeometryCollection, DeepEarth.Toolkit.Geometry">
                    <StackPanel Orientation="Horizontal" Margin="0 0 5 0">
                        <TextBlock Text="Geometry Collection" Foreground="White" Margin="0 0 5 0"></TextBlock>
                    </StackPanel>
                </DataTemplate>
                
            </deepearth:TemplateSelector>
            
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition Width="250"></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <deepearth:Map x:Name="map" GeoItems="{StaticResource geoItems}" TemplateSelector="{StaticResource mapTemplateSelector}">
            <deepearth:Map.View>
                <deepearth:MapView>
                    <deepearth:MapView.TileSourceProvider>
                        <nearmap:NearMapTileSourceProvider Mode="PhotoMap"></nearmap:NearMapTileSourceProvider>
                    </deepearth:MapView.TileSourceProvider>
                </deepearth:MapView>
            </deepearth:Map.View>
        </deepearth:Map>
        
        <deepearth:NavigationPanel x:Name="navigationPanel" Map="{Binding ElementName=map}">
            <deepearth:NavigationPanel.VerticalPanel>
                <deepearth:Digitizer Orientation="Vertical" Map="{Binding ElementName=map}" GeoItems="{StaticResource geoItems}"></deepearth:Digitizer>
            </deepearth:NavigationPanel.VerticalPanel>
        </deepearth:NavigationPanel>

        <deepearth:ReorderableLayerPanel Grid.Column="1" GeoItems="{StaticResource geoItems}" TemplateSelector="{StaticResource layerTemplateSelector}" />       

    </Grid>

</navigation:Page>
